<?php

class OptionController extends Zend_Controller_Action
{
	private $_userInfo;
    public function init ()
    {
        $acl = new My_Acl();
        $auth = $acl->checkAllowed($this->_request);
        $this->_userInfo = $auth->getIdentity();
    }
    public function indexAction ()
    {
		$config = new Zend_Config_Ini(CONFIG_PATH . '/columns.ini',APPLICATION_ENV);
        
        $model_option           = new Default_Model_Option();
        $model_roleoption       = new Default_Model_Rolesoption();
        if($this->getRequest()->isPost())
    	{
    		$option_post = $this->_request->getPost();
            if(isset($option_post['option'])){
                $option_post = json_encode($option_post['option']);
                $model_option->updateOption($this->_userInfo['userId'], $option_post);
                $this->view->message ="Đã lưu";
                $this->view->success ="success";
            }else{
                $this->view->message ="Bạn phải chọn tối thiểu 1 thuộc tính";
                $this->view->success ="warning";
            }
        }
        
        $option_user = $model_option->getOptions($this->_userInfo['userId']);
        $option_user = $option_user->toArray();
        $option_user = json_decode($option_user['name']);
        
        $option_role = $model_roleoption->getDataByUserId($this->_userInfo['userId'])->toArray();
        $temp = array();
        foreach($option_role as $row){
            $temp = array_merge($temp, json_decode($row['views']));
        }
        $temp = array_unique($temp);
        $option_role = array_values($temp);
        
        $option = array_intersect($option_user, $option_role);
        $this->view->option = $option;
        $viewsConfig = $config->views->toArray();
        $this->view->viewsConfig = $viewsConfig;
        //echo '<pre>',print_r($viewsConfig),'</pre>';exit();
    }
}



